package kwic.ms;

@SuppressWarnings("unchecked")
public class MyCharArray implements Comparable {
	private char[] chars;
	private int index;
	private int start;
	private int num;

	public MyCharArray(char[] chars, int start, int num, int index) {
		this.setChars(chars);
		this.setStart(start);
		this.setNum(num);
		this.setIndex(index);
	}

	@Override
	public int compareTo(Object o) {
		MyCharArray myCharArray = (MyCharArray) o;
		char[] chars1 = myCharArray.getChars();
		int num1 = myCharArray.getNum();
		int start1 = myCharArray.getStart();

		int i = 0;
		while (i < num && i < num1 && chars[start + i] == chars1[start1 + i])
			i++;
		if (i < num && i < num1) {
			return chars[start + i] - chars1[start1 + i];
		} else {
			return num - num1;
		}
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getStart() {
		return start;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getNum() {
		return num;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public int getIndex() {
		return index;
	}

	public void setChars(char[] chars) {
		this.chars = chars;
	}

	public char[] getChars() {
		return chars;
	}

}
